﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;

namespace AteneoLibri.Utility.Mail
{
    public class MailSettings
    {
        private string _smtpServer = string.Empty;
        /// <summary>
        /// Server SMTP utilizzato per l'invio della mail.
        /// </summary>
        public string SmtpServer
        {
            get { return this._smtpServer; }
        }

        private string _smtpPort = string.Empty;
        /// <summary>
        /// Porta del server SMTP utilizzato per l'invio della mail.
        /// </summary>
        public string SmtpPort
        {
            get { return this._smtpPort; }
        }

        private string _mailSender = string.Empty;
        /// <summary>
        /// Indirizzo email utilizzato come mittente.
        /// </summary>
        public string MailSender
        {
            get { return this._mailSender; }
        }

        private string _senderDisplayName = string.Empty;
        /// <summary>
        /// Nome descrittivo visualizzato relativo dell'indirizzo email utilizzato come mittente.
        /// </summary>
        public string SenderDisplayName
        {
            get { return this._senderDisplayName; }
        }

        private string _userName = string.Empty;
        /// <summary>
        /// Username per l'accesso al server SMTP.
        /// </summary>
        public string UserName
        {
            get { return this._userName; }
        }

        private string _password = string.Empty;
        /// <summary>
        /// Password per l'accesso al server SMTP.
        /// </summary>
        public string Password
        {
            get { return this._password; }
        }

        private MailSettings()
        {
        }

        /// <summary>
        /// Restituisce una nuova istanza valorizzata della classe MailSettings.
        /// </summary>
        /// <returns></returns>
        public static MailSettings Create()
        {
            MailSettings mailSettings = new MailSettings();
            mailSettings._smtpServer = ConfigurationManager.AppSettings["MAIL_SmtpServer"].ToString();
            mailSettings._smtpPort = ConfigurationManager.AppSettings["MAIL_SmtpPort"].ToString();
            mailSettings._mailSender = ConfigurationManager.AppSettings["MAIL_Sender"].ToString();
            mailSettings._senderDisplayName = ConfigurationManager.AppSettings["MAIL_SenderDisplayName"].ToString();

            mailSettings._userName = ConfigurationManager.AppSettings["MAIL_CredentialUserName"].ToString();
            mailSettings._password = ConfigurationManager.AppSettings["MAIL_CredentialPassword"].ToString();

            return mailSettings;
        }

        public static MailSettings Create(string mailSender)
        {
            MailSettings mailSettings = new MailSettings();
            mailSettings._smtpServer = ConfigurationManager.AppSettings["MAIL_SmtpServer"].ToString();
            mailSettings._smtpPort = ConfigurationManager.AppSettings["MAIL_SmtpPort"].ToString();
            mailSettings._mailSender = mailSender;
            mailSettings._senderDisplayName = ConfigurationManager.AppSettings["MAIL_SenderDisplayName"].ToString();

            mailSettings._userName = ConfigurationManager.AppSettings["MAIL_CredentialUserName"].ToString();
            mailSettings._password = ConfigurationManager.AppSettings["MAIL_CredentialPassword"].ToString();

            return mailSettings;
        }

        public static MailSettings Create(string mailSender, string mailPassword)
        {
            MailSettings mailSettings = new MailSettings();
            mailSettings._smtpServer = ConfigurationManager.AppSettings["MAIL_SmtpServer"].ToString();
            mailSettings._smtpPort = ConfigurationManager.AppSettings["MAIL_SmtpPort"].ToString();
            mailSettings._mailSender = mailSender;
            mailSettings._senderDisplayName = ConfigurationManager.AppSettings["MAIL_SenderDisplayName"].ToString();
            mailSettings._userName = mailSender;
            mailSettings._password = mailPassword;

            return mailSettings;
        }
    }
}